<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>大品牌管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/zTreeStyle/demo.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
       <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/sc/js/page.js"></script>
    <style>
       
       #alertmod_table_list_2 {
            top: 900px !important;
        }
         .alerts{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgba(0,0,0,0.5);}
       .alerts .alerts_content{background:#fff;position: fixed;top: 50%;left: 50%; width: 700px;min-height: 500px;margin: -220px 0 0 -350px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
        .wait{ display:none;background:#f4f4f5;position: fixed;top: 50%;left: 50%; width: 700px;min-height: 250px;margin: -220px 0 0 -350px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
       .alerts .alerts_content h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 99%;margin-bottom:30px;background: #d0e0e0}
       .alerts .alerts_content .alerts_form{
        width:100%;
       }
         .alert_addNewZone_tree{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgba(0,0,0,0.5);}
       .alert_addNewZone_tree .alert_addNewZone_content_tree{background:#fff;position: fixed;top: 50%;left: 50%; width: 500px;height: 300px;margin: -150px 0 0 -250px;border:4px solid #ccc;box-sizing: border-box;overflow: hidden;/* margin 负值为宽高的一半 */}
       .alert_addNewZone_tree .alert_addNewZone_content_tree h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 100%;background: #d0e0e0}
       .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form{
        width:100%;
       }
       .alert_addNewZone_tree .alert_addNewZone_content_tree .alert_addNewZone_form_tree{
        height: 280px;
        width: 100%;
        overflow-x: hidden;
        overflow-y: auto;
       }
       .alerts .alerts_content .alerts_form form{width: 100%;}
       .alerts .alerts_content .alerts_form form div{margin-bottom:30px;width: 100%;text-align: center;}
       .alerts .alerts_content .alerts_form form div label{display:inline-block;width: 130px;text-align: right;}
       .alerts .alerts_content .alerts_form form div:nth-of-type(1) input{margin-right: 28px;}
        .mtp{margin-top:3px;}
        .no-padding{padding: 0;}
        #gopage{color:blue;cursor: pointer;}
        #firstpage{cursor: pointer;}


           .alert_addNewZone_tree{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgb(255,255,255,0.7);z-index: 200}
       .alert_addNewZone_tree .alert_addNewZone_content_tree{background:#fff;position: fixed;top: 50%;left: 50%; width: 500px;height: 350px;margin: -150px 0 0 -250px;border:4px solid #ccc;box-sizing:border-box;overflow: hidden;/* margin 负值为宽高的一半 */}
       .wait,.waits{background:#f4f4f5;position: fixed;top: 50%;left: 50%; width: 500px;height: 300px;margin: -150px 0 0 -250px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
       .alert_addNewZone_tree .alert_addNewZone_content_tree h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 100%;background: #d0e0e0}
    </style>
</head>

<body class="white-bg" style="color:#333;">
          <div class="page-heade">
       <h2 class="title_color text-center">产品大品牌管理</h2>
    </div>
        <div class="col-md-12 mtp" style="padding:3px;">
			<table class="table" style="width: 100%;">
					<tbody>
						<tr>
							<td>
								<input type="button" value="新增" class="btn btn-info add"/> 
                                <input type="button" value="导入" class="btn btn-info"/> 
                               
	            				
							</td>
						</tr>
						<form action="#" method="post" id="form_check" class="form-inline formpage">
							 <input type="hidden" value='{$page}' name="page" id="page-go"/>
                			<input type="hidden" value='{$list}' name="list" id="list-go"/>
                			<tr>
								<td style="font-size: 14px;">
									模糊查询:
								<div class="form-group" style="display: inline-block;">  产品大品牌编号:<input type="text" value='{$data.big_no}' style="width:140px;display: inline-block;" name="big_no" class="form-control" /></div><span class="lr_5"></span>
									<div class="form-group" style="display: inline-block;">产品大品牌:<input type="text" value='{$data.big_name}'  style="width:140px;display: inline-block;"  name="big_name" class="form-control" /></div><span class="lr_5"></span>
									
									<input type="button" value="查询" class='btn btn-info' id="check"/><span class="lr_5"></span>
									<input type="button" value="清空查询条件" class='btn btn-info' id="clear_check"/><span class="lr_5"></span>
									<input type="button" value="导出Excel" class='btn btn-info' id="dc"/>
								</td>
                			</tr>
						</form>
					</tbody>
				</table>
				{if condition="$sum neq 0"}
				<table class="table table-hover table-bordered bud_hei table-striped text-center" style="width: 100%;">
					<thead>
						<tr class='info'>
							<td style="width:5%;">序号</td>
							<td style="width:10%;">大品牌编号</td>
							<td style="width:10%;">大品牌名称</td>
							<td style="width:25%;">包含品牌</td>
							<td style="width:10%;">创建人</td>
							<td style="width:10%;">创建时间</td>
							<td style="width:10%;">修改人</td>
							<td style="width:10%;">修改时间</td>
							<td style="width:10%;">操作</td>
						</tr>
						
					</thead>
					<tbody>
						{volist name="pro_bs" id="vo"}
							<tr style="font-size: 14px;">
								<td style="width:5%;">{$i}</td>
								<td style="width:10%;">{$vo.big_no}</td>
								<td style="width:10%;">{$vo.big_name}{if condition="$vo.is_actived eq 0"}(已删除){/if}</td>
								<td style="width:25%;">
									{volist name="barr" id="voi" key="j"}
										{if condition="$voi.big_id eq $vo.id"}
											&nbsp;{$voi.brand_name}&nbsp;
										{/if}
									{/volist}
								</td>
								<td style="width:10%;">{$vo.cname}</td>
								<td style="width:10%;">{$vo.created_on}</td>
								<td style="width:10%;">{$vo.mname}</td>
								<td style="width:10%;">{$vo.modifiled_on}</td>
								<td style="width:10%;"  bid='{$vo.id}'>
									{if condition="$vo.is_actived eq 1"}
									<a href="javascript:;" class='updatabb'>修改</a>
									<a href="javascript:;" class='dropbb'>删除</a>
									{else/}
									<a href="javascript:;" class='huifubb'>恢复</a>
									{/if}
								</td>
							</tr>
						{/volist}
						
					</tbody>

				</table>
				<h5 class="text-center" id="pagesc" style="font-size: 16px;font-weight: 500">
            <script>
                            $(function(){
                                pageSC("pagesc",{$sum},{$page},{$maxpage})
                            })
                        </script>
					每页显示
					<select id="pagesize">
						<option value='10' {if condition="$list eq 10"}selected{/if}>10条</option>
						<option value='15'{if condition="$list eq 15"}selected{/if}>15条</option>
						<option value='20'{if condition="$list eq 20"}selected{/if}>20条</option>

					</select>
				</h5>
				{else/}
				<h3>对不起没有查询到符合条件的信息</h3>
				{/if}
			
        </div>
  <!--新增弹框-->
	<div class="alert_addbar alerts">
        <div class="alerts_content animated fadeIn">
            <h3><span id="istj">添加品牌</span><a style="float: right;margin-right: 10px;font-size: 30px" id="del_this">&times;</a></h3>
            <div  class="alerts_form">
                <form id="newbar" class="form-inline">
                   	<table class="table table-bordered bud_hei">
							<input type="hidden" value="0" id="isupdate"/>
							<tr>
								<td class="text-right" >产品大品牌编号<span style="color: red">*</span>:</td>
								<td><input type="text" class="form-control"  id="big_no"/><span style="font-size:12px; color:red;">(提示:如不填写系统将会自动分配)<span></td>
							</tr>
							<tr>
								<td class="text-right" >产品大品牌名称<span style="color: red">*</span>:</td>
								<td><input type="text" class="form-control"  id="big_name"/>(不能重复)</td>
							</tr>
							<tr>
								<td class="text-right" >包含品牌<span style="color: red">*</span>:</td>
								<td>
								 <span id="pb_kg"></span>
                                 <input type="hidden" id="pb_id" value=""/>
								<a href="javascript:;" id="choose_pb">选择</a></td>
                                    
							</tr>
						
                   	</table>
                   	<div class="row text-center">

                        
						<input type="button" value="保存" id="bc" class="btn btn-success"/>
                       
                   	</div>
                </form>
            </div>
        </div>
        <div class="wait">
   				<div class="ibox ">
                    <div class="ibox-title">
                        <h5>正在处理，请稍后.....</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="spiner-example">
                            <div class="sk-spinner sk-spinner-chasing-dots">
                                <div class="sk-dot1"></div>
                                <div class="sk-dot2"></div>
                            </div>
                        </div>
                    </div>
                </div>

	        </div>
    </div>
        <!--新增弹框-->
          <!--树状弹框-->
        <div class="alert_addNewZone_tree">
            <div class="alert_addNewZone_content_tree">
                <h3><span id="txtree"></span><a style="float: right;margin-right: 10px;font-size: 30px" id="del_this1">&times;</a></h3>
                <div  class="alert_addNewZone_form_tree" id="fenqu_fzr">
                  <ul id="tree_em" class="ztree"></ul>
                   <div class="quedingbtn" style="position: absolute;right: 0;bottom: 10px;"><button class="btn btn-success" id="qd">确定</button></div>
                </div>
                
            </div>
            <div class="wait">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>正在处理，请稍后.....</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="spiner-example">
                            <div class="sk-spinner sk-spinner-chasing-dots">
                                <div class="sk-dot1"></div>
                                <div class="sk-dot2"></div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         </div>
        <!--树状弹框-->
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
     <!-- Peity -->
    <script src="__STATIC__/layout/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- 自定义js -->
    <script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>
     <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    
    <!-- ztree -->
    <script type="text/javascript" src="__STATIC__/zTreeStyle/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="__STATIC__/zTreeStyle/jquery.ztree.excheck.js"></script>
    <!--统计代码，可删除-->
	<script>
        //删除
        $(".dropbb").click(function(){
             var bid=$(this).parent().attr("bid");
            swal({
                            title: "提示",
                            text: "您真的要删除这个大品牌么？",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#FF3333",
                            confirmButtonText: "是的我要删除",
                            cancelButtonText: "取消",
                            closeOnConfirm: true
                        },
                        function (isConfirm) {
                           if (isConfirm) {
                            $.post("{:url('Productsbrands/dropbb')}",{bid:bid},function(re){
                                if(re==1){
                                    swal({
                                    title: "完成",
                                    text:  "大品牌已删除",
                                    type: "success"
                                    },function(){
                                        document.getElementById("form_check").submit();
                                    });
                                }else{
                                     swal({
                                    title: "错误",
                                    text:  "系统繁忙请稍后再试",
                                    type: "warning"
                                    });
                                }
                            })
                        }
                        })
                           
        })
         $(".huifubb").click(function(){
             var bid=$(this).parent().attr("bid");
            swal({
                            title: "提示",
                            text: "您真的要恢复这个大品牌么？",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#33FF33",
                            confirmButtonText: "是的我要恢复",
                            cancelButtonText: "取消",
                            closeOnConfirm: true
                        },
                        function (isConfirm) {
                           if (isConfirm) {
                            $.post("{:url('Productsbrands/huifubb')}",{bid:bid},function(re){
                                if(re==1){
                                    swal({
                                    title: "完成",
                                    text:  "大品牌已恢复",
                                    type: "success"
                                    },function(){
                                       document.getElementById("form_check").submit();
                                    });
                                }else{
                                     swal({
                                    title: "错误",
                                    text:  "系统繁忙请稍后再试",
                                    type: "warning"
                                    });
                                }
                            })
                        }
                        })
                           
        })
		//添加部门弹框
        $(".add").click(function(){
             $("#isupdate").val(0);
            $(".alert_addbar").show();
            $(".alert_addbar input[type=text]").val("");
            $("#pb_kg").html("");
            $("#istj").html("添加大品牌");
        });
        //修改部门弹框
        $(".updatabb").click(function(){
            var bid=$(this).parent().attr("bid");
            $.post("{:url('Productsbrands/getbigbrand')}",{bid:bid},function(re){
               // alert(re);
                var arr=JSON.parse(re);
                var bigbrands=arr["big_brand"];
                var brandarr=arr["brands_arr"];
                $("#isupdate").val(bigbrands["id"]);
                $("#big_no").val(bigbrands["big_no"]);
                $("#big_name").val(bigbrands["big_name"]);
				$("#pb_kg").html("");
				for(var i=0;i<brandarr.length;i++){
					$("#pb_kg").append("<span rid='"+brandarr[i]["id"]+"' style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;margin-right:5px'>"+brandarr[i]["brand_name"]+"&nbsp;&nbsp;<span onclick='qxrg("+brandarr[i]["id"]+");' style='cursor:pointer;font-size:16px'>x</span></span>");
				}

                $(".alert_addbar").show();
           
                $("#istj").html("编辑大品牌");
            })
        })
        $("#del_this").click(function(){
            $(".alert_addbar").hide();
             $("#isupdate").val(0);
            $(".alert_addbar input[type=text]").val("");
           
           
        });
        var regex=/^[a-zA-Z0-9_()（）\u4e00-\u9fa5]{1,20}$/;
        var regex_no=/^[a-zA-Z0-9_\-]{1,20}$/;
        //点击保存
        $("#bc").click(function(){
        	var error="";
        	var bids=get_choose_other_role();
        	//验证
        	if($("#big_name").val()==""){
        		error="大品牌名不能为空";
        	}else if(!regex.test($("#brands_name").val()) ){
        		error="大品牌名为字母，数字，下划线，中文 可以包含()长度不超过20";
        	}else if($("#big_no").val()!=""){
        		if(!regex_no.test($("#big_no").val())){
        			error="大品牌编号为字母，数字，下划线，长度不超过20";
        		}
				
        	}else if(bids==""){
        		error="至少分配一个品牌";
        	}
        	if(error!=""){
        		swal({
					title: "错误",
					text:  error,
					type: "warning"
				});
        	}else{
        		$(".alerts_content").hide();
        		$(".wait").show();
        		
        		$.post("{:url('Productsbrands/new_big_brand')}",{id:$("#isupdate").val(),big_name:$("#big_name").val(),big_no:$("#big_no").val(),bids:bids},function(re){
                    $(".alerts_content").show();
                    $(".wait").hide();
                    //alert(re);
        				if(re==1){
                            swal({
                                title: "完成",
                                text:  "操作已成功",
                                type: "success"
                            },function(){
                                location.href='{:url("Productsbrands/bigbrands")}';
                            });
                        }else{
                            var errormsg="";
                            switch(re){
                                case 2:errormsg="大品牌名不能为空";break;
                                case 4:errormsg="大品牌已存在";break;
                                 case 7:errormsg="大品牌编号已存在";break;
                                case 3:errormsg="至少分配一个品牌";break;
                                default:errormsg="系统繁忙请稍后再试";break;
                            }
                            swal({
                                title: "错误",
                                text: errormsg,
                                type: "warning"
                            });

                        }
        		})
        	}

        })
         //翻页
      
        $("#check").click(function(){
        	  $("#page-go").val(1);
              document.getElementById("form_check").submit();
        })
        $("#clear_check").click(function(){
        	$("input[type='text']").val("");
        	$("#page-go").val(1);
        	 document.getElementById("form_check").submit();
        })
         function qxrg(rid){
          $("#pb_kg span[rid='"+rid+"']").remove();
    }
 function disabledNode(e) {
            var zTree = $.fn.zTree.getZTreeObj("tree_em"),
            disabled = e.data.disabled,
            nodes = zTree.getSelectedNodes();
            if (nodes.length == 0) {
                alert("请先选择一个节点");
            }

            for (var i=0, l=nodes.length; i<l; i++) {
                zTree.setChkDisabled(nodes[i], disabled);
            }
        }
         //角色组树
         //设定
            var setting_rg = {
            check: {
                enable: true,
                chkboxType: { "Y": "", "N": "" }
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                onCheck: rgOnCheck
            }
        };
        function get_choose_other_role(){
        var other_dei=0;
        var other_de_arr=new Array();
        $("#pb_kg>span").each(function(){
            other_de_arr[other_dei]=$(this).attr("rid");
            other_dei++;
        })
        return other_de_arr.join(',');
    }
          //树选择
        function rgOnCheck(event, treeId, treeNode) {
            if(treeNode.checked==true){
                   
                var flag=0;
                
                $("#pb_kg span").each(function(){
                    if(parseInt($(this).attr("rid"))==parseInt(treeNode.id)){
                        flag=1;
                    }   
                    
                })
                if(flag==0){
                    var str="<span rid='"+treeNode.id+"' style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;margin-right:5px'>"+treeNode.name+"&nbsp;&nbsp;<span onclick='qxrg("+treeNode.id+");' style='cursor:pointer;font-size:16px;'>x</span></span>";
                    $("#pb_kg").append(str);
                }
                
                
            }else{
                $("#pb_kg span[rid='"+treeNode.id+"']").remove();
            }
        }
 
        $("#choose_pb").click(function(){
            $(".alert_addNewZone_tree").show();
                $("#txtree").html("品牌列表");
                $("#fenqu_fzr").hide();
                $(".wait").show();
                var rids=get_choose_other_role();
               // alert(rids);
               $.post("{:url('Productsbrands/getbrandlist_duo')}",{rids:rids},function(re){
                //alert(re);
                
                    var data_ode=JSON.parse(re);
                    
                    $("#fenqu_fzr").show();
                    $(".wait").hide();
                    $.fn.zTree.init($("#tree_em"), setting_rg, data_ode);
                    $("#disabledTrue").bind("click", {disabled: true}, disabledNode);
                    $("#disabledFalse").bind("click", {disabled: false}, disabledNode);
               })
        })
     //关闭树
        
        $("#del_this1").click(function(){
             
            $(".alert_addNewZone_tree").hide();
        })
        $("#qd").click(function(){
            
            $(".alert_addNewZone_tree").hide();
        })
	</script>
</body>

</html>
